import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    username: '',
    tabsList: [
      {
        path: '/',
        name: 'home',
        label: '首页',
        icon: 'home'
      }
    ]
  },
  getters: {},
  mutations: {
    closeTab(state, val) {
      let result = state.tabsList.findIndex(item => item.name === val.name)
      state.tabsList.splice(result, 1)
      window.sessionStorage.setItem('tagList', JSON.stringify(state.tabsList))
    },
    selectMenu(state, val) {
      let result = state.tabsList.findIndex(item => item.name === val.name)
      result === -1 ? state.tabsList.push(val) : ''
      window.sessionStorage.setItem('tagList', JSON.stringify(state.tabsList))
    },
    getMenu(state) {
      if (window.sessionStorage.getItem('tagList')) {
        let tagList = JSON.parse(window.sessionStorage.getItem('tagList'))
        state.tabsList = tagList
      }
    }
  },
  actions: {},
  modules: {}
})
